package cn.fl.risk.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.*;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstCorpBscInfoService;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.transform.CstBscInfoVOTransform;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstCorpBscInfoVO;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.product.service.ISplInfoService;
import cn.fl.product.vo.SplInfoVO;
import cn.fl.project.condition.PrjBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjPrdPaySchMQueryCondition;
import cn.fl.project.constant.PrjPrdPaySchMConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjLnkCompService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjPrdPaySchMService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjLnkCompVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjPrdPaySchMVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.risk.condition.RskCstSignLogQueryCondition;
import cn.fl.risk.constant.RiskCstSignLogConstant;
import cn.fl.risk.constant.RskSignOperLogConstant;
import cn.fl.risk.service.IRskCstSignLogService;
import cn.fl.risk.service.IRskSignOperLogService;
import cn.fl.risk.util.ComparatorDate;
import cn.fl.risk.vo.RskCstSignLogVO;
import cn.fl.risk.vo.RskSignOperLogVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.customer.facade.customer.condition.CstBscInfoQueryCondition;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplRelLogBizTypCdNum;
import fl.spl.facade.lnkcomp.condition.PrjLnkCompQueryCondition;
import fl.spl.facade.spl.condition.SplInfoQueryCondition;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description: 客户风险标记记录表 控制层
 */
@Controller
@RequestMapping("/risk/rskCstSignLog")
public class RskCstSignLogController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(RskCstSignLogController.class);

    /**
     * RskCstSignLog 服务层BEAN
     */
    @Autowired
    private IRskCstSignLogService rskCstSignLogService;

    @Autowired
    private IPrjBscInfoService prjBscInfoService;// 项目基础信息表

    @Autowired
    private IFriBaseInfoService friBaseInfoService;// 融资机构基础信息表

    @Autowired
    private ICstBscInfoService cstBscInfoService;// 客户基础信息表

    @Autowired
    private IPrjPrdPaySchMService prjPrdPaySchMService;// 项目支付信息表

    @Autowired
    private ICstNpBscInfoService cstNpBscInfoService;// 自然人客户

    @Autowired
    private ICstCorpBscInfoService cstCorpBscInfoService;// 法人客户

    /**
     * 客户风险标记日志表
     */
    @Autowired
    private IRskSignOperLogService rskSignOperLogService;

    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;//项目产品明细信息表

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    @Autowired
    private ISplInfoService splInfoService;

    @Autowired
    private IPrjLnkCompService prjLnkCompService;

    /**
     * 到风险标记管理列表页面
     */
    @RequestMapping(value = "/toRskSignListPage.do", method = {RequestMethod.GET})
    public ModelAndView toRskSignListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载到风险标记管理列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskSignList");
        return mav;
    }

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载RskCstSignLog列表页面.", CurrentThreadContext.getCurrentUserName());
        String cstId = request.getParameter("cstId");
        String cstNm = request.getParameter("cstNm");
        String signSource = request.getParameter("signSource");
        String cstIdcard = request.getParameter("cstIdcard");
        // 直接进入新增页面的Flag
        //String toAddFlag = request.getParameter("toAddFlag");
        // 跳转的页面model对象
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogList");
        // 查询数据库字典，查询客户风险标记原因
        //List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 查询数据库字典，查询客户风险标记类型
        //List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);

        // 查询数据库字典，查询客户风险标记类型
        List<KeyValueVO> signSourceList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_SING_SOURCE);

        mav.addObject("signSourceList", signSourceList);
        //mav.addObject("signResCdList", signResCdList);
        //mav.addObject("signResTypeList", signResTypeList);
        mav.addObject("cstId", cstId);
        mav.addObject("cstNm", cstNm);
        mav.addObject("signSource", signSource);
        mav.addObject("cstIdcard", cstIdcard);
        //mav.addObject("toAddFlag", toAddFlag);
        return mav;
    }
    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toDetailListPage.do", method = {RequestMethod.GET})
    public ModelAndView toDetailListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toDetailListPage", "加载RskCstSignLog列表页面.", CurrentThreadContext.getCurrentUserName());
        String cstId = request.getParameter("cstId");
        String cstNm = request.getParameter("cstNm");
        String signSource = request.getParameter("signSource");
        String cstIdcard = request.getParameter("cstIdcard");
        String cstTypeCd = request.getParameter("cstTypeCd");
        // 跳转的页面model对象
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogDetailList");
        // 查询数据库字典，查询客户风险标记原因
        mav.addObject("cstId", cstId);
        mav.addObject("cstNm", cstNm);
        mav.addObject("signSource", signSource);
        mav.addObject("cstIdcard", cstIdcard);
        mav.addObject("cstTypeCd", cstTypeCd);
        return mav;
    }


    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toChooseCstPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toChooseCstPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("risk/rskCstSignLog/custCstBscInfoList");

        List<KeyValueVO> signSourceList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_SING_SOURCE);

        view.addObject("signSourceList", signSourceList);
        view.addObject("signSource", SplRelLogBizTypCdNum.CST.getBizTypCd());
        BaseLogUtils.info(logger, "toListPage", "跳转到客户列表页面", CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 跳转到选择项目列表页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toChoosePrjPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toChoosePrjPage(HttpServletRequest request, HttpServletResponse response) {
        logger.info("加载PrjBscInfo列表页面.");
        ModelAndView view = new ModelAndView(
                "risk/rskCstSignLog/projectPrjBscInfoList");
        String currentOrgCd = CurrentThreadContext.getCurrentOrgCd();
        /*if(currentOrgCd.length()>8){
            if(CollectionUtils.isNotEmpty(orgList)){
                for(KeyValueVO kv:orgList){
                    if(kv.getKey().equals(currentOrgCd.substring(0, 8))){
                        view.addObject("currOrg", CurrentThreadContext.getCurrentOrgCd());
                        break;
                    }
                }
            }
        }*/
        Pager page = new Pager();
        page.setCurrentPage(1);
        page.setEveryPage(Integer.MAX_VALUE);
        FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
        qc.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
        qc.setInsUseCd("2");
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        page.setCondition(qc);
        Pager pager = this.friBaseInfoService.searchListPage(page);
        List<FriBaseInfoVO> list = (List<FriBaseInfoVO>) pager.getResultList();
        view.addObject("friBaseList", list);
        view.addObject("queryFlag", "query");// 查询列表隐藏操作按钮
        //view.addObject("updateFlag", "update");//业务移交、供应商修改
        view.addObject("currentBuOrgCd",
                CurrentThreadContext.getCurrentBuOrgCd());
        return view;
    }

    /**
     * 初始化可选择的项目列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initPrjList4Rsk.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initPrjList4Rsk(HttpServletRequest request,
                                  HttpServletResponse response) {
        // 参数
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String prjNm = request.getParameter("prjNm");
        String cstNm = request.getParameter("cstNm");
        String lsCntNo = request.getParameter("lsCntNo");
        String ovdViewFlag = request.getParameter("ovdViewFlag");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjBscInfoQueryCondition qc = new PrjBscInfoQueryCondition();
        if (StringUtils.isNotBlank(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotBlank(prjNm)) {
            qc.setPrjNm(prjNm);
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        page.setCondition(qc);
        Pager pager = this.prjBscInfoService.searchListPage(page);
        List<PrjBscInfoVO> list = (List<PrjBscInfoVO>) pager.getResultList();
        List<PrjBscInfoVO> prjBscInfoVOListWithoutlsCntNo = new ArrayList<>();
        // 循环遍历出所有存在合同号的
        for (PrjBscInfoVO prjBscInfoVO : list) {
            if (prjBscInfoVO.getLsCntNo() != null && prjBscInfoVO.getLsCntNo() != "") {
                prjBscInfoVOListWithoutlsCntNo.add(prjBscInfoVO);
            }
        }
        if (CollectionUtils.isNotEmpty(list) && "ovdViewFlag".equals(ovdViewFlag)) {
            this.prjBscInfoService.putOvdDataToPrjBscInfo(list);
        }
        ListPageVO<PrjBscInfoVO> listPage = new ListPageVO<PrjBscInfoVO>(prjBscInfoVOListWithoutlsCntNo,
                pager.getTotalCount());
        return listPage;
    }

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPage", "加载RskCstSignLog Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogDetail");
        //this.prepare(request,mav);
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long id = Long.parseLong(request.getParameter("id"));
        // 获取当前风险标记对象
        RskCstSignLogVO rskCstSignLogVO = this.rskCstSignLogService.selectById(Long.valueOf(id));
        // 获取项目id
        Long prjId = rskCstSignLogVO.getPrjId();
        if (StringUtils.isNotEmpty(prjId)) {
            // 设置查询条件，查询设备数量
            PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
            qc.setPrjId(prjId);
            qc.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
            // 支付表主表信息
            List<PrjPrdPaySchMVO> prjPrdPaySchMVOList = prjPrdPaySchMService.searchList(qc);

            // 获取保证金
            Long arAmt = prjPrdPaySchMService.searchAramtByPrjId(prjId);
            if (arAmt == null) {
                arAmt = 0L;
            }
            // 获取剩余本金
            Long restCorpus = prjPrdPaySchMService.selectRestCorpus(prjId);
            if (restCorpus == null) {
                restCorpus = 0L;
            }
            // 当前敞口
            Long open = restCorpus - arAmt;
            // 获取最早起租日期
            String earlistRtDt = "";
            // 融资额计算
            Double temp = 0d;
            // 保存所有日期
            List<Date> dates = new ArrayList<>();
            if (prjPrdPaySchMVOList.size() > 1) {
                for (int i = 0; i < prjPrdPaySchMVOList.size(); i++) {
                    Date date = prjPrdPaySchMVOList.get(i).getLsDt();
                    if (date != null) {
                        dates.add(date);
                    }
                    // 计算融资额
                    temp += prjPrdPaySchMVOList.get(i).getActLsAmt();
                }
                if (dates.size() != 0) {
                    ComparatorDate c = new ComparatorDate();
                    Collections.sort(dates, c);
                    earlistRtDt = sdf.format(dates.get(0));
                }
            } else if (prjPrdPaySchMVOList.size() == 1) {
                Date lsDt = prjPrdPaySchMVOList.get(0).getLsDt();
                if (lsDt != null) {
                    earlistRtDt = sdf.format(prjPrdPaySchMVOList.get(0).getLsDt());
                }
                temp = prjPrdPaySchMVOList.get(0).getActLsAmt();
            }
            // 数据精度的格式化
            java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
            nf.setGroupingUsed(false);
            String actLsAmt = nf.format(temp);

            // 获取用户基础信息
            CstBscInfoVO cstBscInfoVO = prjBscInfoService.getCstTypByPrjId(prjId);
            // 获取项目基础信息
            PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjId);

            // 查询数据库字典，查询项目类型
            List<KeyValueVO> prjTypeList = this.sysDictionaryApiService.getKvListAll(DictionaryConstant.CODE_PRJ_TYPE_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
//            List<KeyValueVO> prjTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_PRJ_TYPE_CD);
            // 查询数据库字典，查询事业部
            List<KeyValueVO> buOrgList = this.cstBscInfoService.searchBusinessOrgList();
            PrjPrdPaySchMVO pay = null;
            // 客户信息
            mav.addObject("cstBscInfoVO", cstBscInfoVO);
            // 项目信息
            mav.addObject("prjBscInfoVO", prjBscInfoVO);
            // 设备数量
            mav.addObject("prdCount", prjPrdPaySchMVOList.size());
            // 项目类型
            mav.addObject("prjTypeList", prjTypeList);
            // 所属事业部
            mav.addObject("buOrgList", buOrgList);
            // 最早起租日期
            mav.addObject("earlistRtDt", earlistRtDt);
            // 融资额
            mav.addObject("actLsAmt", String.valueOf(actLsAmt));
            // 当前敞口
            mav.addObject("open", open);
        }
        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 标记时间
        mav.addObject("crtTm", sdf.format(rskCstSignLogVO.getCrtTm()));

        // mav.addObject("signResCdList", signResCdList);
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("rskCstSignLogVO", rskCstSignLogVO);
        return mav;
    }

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toCstOnlyDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toCstOnlyDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPage", "加载RskCstSignLog Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstOnlySignLogDetail");
        //this.prepare(request,mav);
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long id = Long.parseLong(request.getParameter("id"));
        String cstNm = request.getParameter("cstNm");
        // 获取当前风险标记对象
        RskCstSignLogVO rskCstSignLogVO = this.rskCstSignLogService.selectById(Long.valueOf(id));
        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);

        mav.addObject("crtTm", sdf.format(rskCstSignLogVO.getCrtTm()));
        mav.addObject("cstNm", cstNm);
        // mav.addObject("signResCdList", signResCdList);
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("rskCstSignLogVO", rskCstSignLogVO);
        return mav;
    }


    /**
     * 到客户项目新增页面
     */
    @RequestMapping(value = "/toAddCstPrjPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddCstPrjPage(HttpServletRequest request, HttpServletResponse response) {
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        BaseLogUtils.info(logger, "toAddPage", "加载RskCstSignLog Add页面.", CurrentThreadContext.getCurrentUserName());
        // 获取项目id
        String projectId = request.getParameter("prjId");
        // String类型转换成long
        Long prjId = Long.parseLong(projectId);
        // 设置查询条件，查询设备数量
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        qc.setPrjId(prjId);
        qc.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
        // 支付表主表信息
        List<PrjPrdPaySchMVO> prjPrdPaySchMVOList = prjPrdPaySchMService.searchList(qc);

        // 获取保证金
        Long arAmt = prjPrdPaySchMService.searchAramtByPrjId(prjId);
        if (arAmt == null) {
            arAmt = 0L;
        }
        // 获取剩余本金
        Long restCorpus = prjPrdPaySchMService.selectRestCorpus(prjId);
        if (restCorpus == null) {
            restCorpus = 0L;
        }
        // 当前敞口
        Long open = restCorpus - arAmt;
        // 获取最早起租日期
        String earlistRtDt = "";
        // 融资额计算
        Double temp = 0d;
        // 保存所有日期
        List<Date> dates = new ArrayList<>();
        if (prjPrdPaySchMVOList.size() > 1) {
            for (int i = 0; i < prjPrdPaySchMVOList.size(); i++) {
                Date date = prjPrdPaySchMVOList.get(i).getLsDt();
                if (date != null) {
                    dates.add(date);
                }
                // 计算融资额
                temp += prjPrdPaySchMVOList.get(i).getActLsAmt();
            }
            if (dates.size() != 0) {
                ComparatorDate c = new ComparatorDate();
                Collections.sort(dates, c);
                earlistRtDt = sdf.format(dates.get(0));
            }
        } else if (prjPrdPaySchMVOList.size() == 1) {
            Date lsDt = prjPrdPaySchMVOList.get(0).getLsDt();
            if (lsDt != null) {
                earlistRtDt = sdf.format(prjPrdPaySchMVOList.get(0).getLsDt());
            }
            temp = prjPrdPaySchMVOList.get(0).getActLsAmt();
        }
        // 数据精度的格式化
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        String actLsAmt = nf.format(temp);

        // 获取用户基础信息
        CstBscInfoVO cstBscInfoVO = prjBscInfoService.getCstTypByPrjId(prjId);
        // 获取项目基础信息
        PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjId);
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogModify");
        // 查询数据库字典，查询项目类型
        List<KeyValueVO> prjTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_PRJ_TYPE_CD);

        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);

        // 查询数据库字典，查询风险标记类型
        List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);

        // 查询数据库字典，查询事业部
        List<KeyValueVO> buOrgList = this.cstBscInfoService.searchBusinessOrgList();

        PrjPrdPaySchMVO pay = null;


        // 客户信息
        mav.addObject("cstBscInfoVO", cstBscInfoVO);
        // 项目信息
        mav.addObject("prjBscInfoVO", prjBscInfoVO);
        // 设备数量
        mav.addObject("prdCount", prjPrdPaySchMVOList.size());
        // 项目类型
        mav.addObject("prjTypeList", prjTypeList);
        // 所属事业部
        mav.addObject("buOrgList", buOrgList);
        // 标记时间
        String crtTm = sdf.format(new Date());
        mav.addObject("crtTm", crtTm);
        // 最早起租日期
        mav.addObject("earlistRtDt", earlistRtDt);
        // 融资额
        mav.addObject("actLsAmt", String.valueOf(actLsAmt));
        // 当前敞口
        mav.addObject("open", open);
        // mav.addObject("signResCdList", signResCdList);
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("signResTypeListJson", JSON.toJSONString(signResTypeList));
        mav.addObject("currentUserName", CurrentThreadContext.getCurrentUserName());
        //this.prepare(request,mav);
        return mav;
    }


    /**
     * 到只有客户新增页面
     */
    @RequestMapping(value = "/toAddCstOnlyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddCstOnlyPage(HttpServletRequest request, HttpServletResponse response) {
        String cstId = request.getParameter("cstId");
        String cstNm = request.getParameter("cstNm");
        String id = request.getParameter("id");
        // 用来判断是详情还是修改
        String flag = request.getParameter("flag");
        RskCstSignLogVO rskCstSignLogVO = null;

        // 获取当前风险标记对象
        if (StringUtils.isNotEmpty(id)) {
            rskCstSignLogVO = this.rskCstSignLogService.selectById(Long.valueOf(id));
        }
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        BaseLogUtils.info(logger, "toAddPage", "加载RskCstSignLog Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstOnlySignLogModify");
        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 查询数据库字典，查询风险标记类型
        List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);
        // 标记时间
        String crtTm = sdf.format(new Date());
        mav.addObject("cstNm", cstNm);
        mav.addObject("cstId", cstId);
        mav.addObject("crtTm", crtTm);
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("signResTypeListJson", JSON.toJSONString(signResTypeList));
        if ("c".equals(flag)) {
            mav.addObject("currentUserName", rskCstSignLogVO.getCrtUsrNm());
        } else {
            mav.addObject("currentUserName", CurrentThreadContext.getCurrentUserName());
        }
        mav.addObject("rskCstSignLogVO", rskCstSignLogVO);
        // 用来判断当前是查看详情还是修改
        mav.addObject("flag", flag);
        //this.prepare(request,mav);
        return mav;
    }


    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPage", "加载RskCstSignLog Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogModify");
        Long id = Long.parseLong(request.getParameter("id"));
        // 获取当前风险标记对象
        RskCstSignLogVO rskCstSignLogVO = this.rskCstSignLogService.selectById(Long.valueOf(id));
        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 查询数据库字典，查询风险标记类型
        List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);
        // 查询数据库字典，查询客户风险标记类型
        List<KeyValueVO> riskTypeCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_TYPE_CD);
        // 查询数据库字典，查询客户风险标记风险来源
        List<KeyValueVO> signSourceList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_SING_SOURCE);
        List<KeyValueVO> isValidList = new ArrayList<>();
        KeyValueVO keyValueVO1 = new KeyValueVO();
        keyValueVO1.setKey("1");
        keyValueVO1.setValue("有效");
        isValidList.add(keyValueVO1);
        KeyValueVO keyValueVO2 = new KeyValueVO();
        keyValueVO2.setKey("0");
        keyValueVO2.setValue("无效");
        isValidList.add(keyValueVO2);
        // 标记时间
        mav.addObject("mdfTm", DateUtils.formatDateToString(new Date(),DateUtils.YYYY_MM_DDHHMMSS));
        mav.addObject("crtTm", DateUtils.formatDateToString(rskCstSignLogVO.getCrtTm(),DateUtils.YYYY_MM_DDHHMMSS));
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("signResTypeListJson", JSON.toJSONString(signResTypeList));
        mav.addObject("riskTypeCdListJson", JSON.toJSONString(riskTypeCdList));
        mav.addObject("signSourceListJson", JSON.toJSONString(signSourceList));
        mav.addObject("isValidListJson", JSON.toJSONString(isValidList));
        mav.addObject("rskCstSignLogVO", rskCstSignLogVO);
        mav.addObject("currentUserName", CurrentThreadContext.getCurrentUserName());
        return mav;
    }


    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toAddPage", "加载RskCstSignLog Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/rskCstSignLogAdd");
        Long cstId = Long.parseLong(request.getParameter("cstId"));
        String cstNm = request.getParameter("cstNm");
        String signSource = request.getParameter("signSource");
        String cstIdcard = request.getParameter("cstIdcard");
        // 获取当前风险标记对象
        RskCstSignLogVO rskCstSignLogVO = new RskCstSignLogVO();
        rskCstSignLogVO.setCstId(cstId);
        if(StringUtils.isNotEmpty(cstIdcard) && !"null".equals(cstIdcard)){
            rskCstSignLogVO.setCstIdcard(cstIdcard);
        }
        rskCstSignLogVO.setCstNm(cstNm);
        rskCstSignLogVO.setSignSource(signSource);
        rskCstSignLogVO.setIsValid(BaseConstant.IS_YESNO_YES);
        rskCstSignLogVO.setSignResType(RiskCstSignLogConstant.CODE_GRP_NM_SIGN_RES_TYPE_3);
        rskCstSignLogVO.setSignResTypeNm("黑名单");
        if(SplRelLogBizTypCdNum.CST.getBizTypCd().equals(signSource)){
            rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.CST.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCdNm(SplRelLogBizTypCdNum.CST.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCd(RiskCstSignLogConstant.CODE_GRP_NM_CST_RISK_TYPE_CD_1);
        }else if(SplRelLogBizTypCdNum.SPL.getBizTypCd().equals(signSource)){
            rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.SPL.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCdNm(SplRelLogBizTypCdNum.SPL.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCd(RiskCstSignLogConstant.CODE_GRP_NM_CST_RISK_TYPE_CD_2);
        }else if(SplRelLogBizTypCdNum.LNK.getBizTypCd().equals(signSource)){
            rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.LNK.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCdNm(SplRelLogBizTypCdNum.LNK.getBizTypCdNm());
            rskCstSignLogVO.setCstTypeCd(RiskCstSignLogConstant.CODE_GRP_NM_CST_RISK_TYPE_CD_3);
        }

            // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 查询数据库字典，查询风险标记类型
        List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);
        // 查询数据库字典，查询客户风险标记类型
        List<KeyValueVO> riskTypeCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_TYPE_CD);
        // 查询数据库字典，查询客户风险标记风险来源
        List<KeyValueVO> signSourceList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_SING_SOURCE);
        List<KeyValueVO> isValidList = new ArrayList<>();
        KeyValueVO keyValueVO1 = new KeyValueVO();
        keyValueVO1.setKey("1");
        keyValueVO1.setValue("有效");
        isValidList.add(keyValueVO1);
        KeyValueVO keyValueVO2 = new KeyValueVO();
        keyValueVO2.setKey("0");
        keyValueVO2.setValue("无效");
        isValidList.add(keyValueVO2);
        // 标记时间
        mav.addObject("crtTm", DateUtils.formatDateToString(new Date(),DateUtils.YYYY_MM_DDHHMMSS));
        mav.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        mav.addObject("signResTypeListJson", JSON.toJSONString(signResTypeList));
        mav.addObject("riskTypeCdListJson", JSON.toJSONString(riskTypeCdList));
        mav.addObject("signSourceListJson", JSON.toJSONString(signSourceList));
        mav.addObject("isValidListJson", JSON.toJSONString(isValidList));
        mav.addObject("rskCstSignLogVO", rskCstSignLogVO);
        mav.addObject("currentUserName", CurrentThreadContext.getCurrentUserName());
        return mav;
    }

    //加载数据字典数据、传值等 ？
    public void prepare(HttpServletRequest request, ModelAndView mav) {

    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object initRskCstSignLogList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        RskCstSignLogQueryCondition qc = new RskCstSignLogQueryCondition();
        // 客户id
        String cstId = request.getParameter("cstId");
        // 客户id
        String cstNm = request.getParameter("cstNm");
        // 合同号
        String lsCntNo = request.getParameter("lsCntNo");
        // 标记人
        String crtUsrNm = request.getParameter("crtUsrNm");
        // 标记原因
        String signResCd = request.getParameter("signResCd");
        //标记类型
        String signResType = request.getParameter("signResType");
        //风险来源
        String signSource = request.getParameter("signSource");
        //证件号码
        String cstIdcard = request.getParameter("cstIdcard");
        //证件号码
        String cstTypeCd = request.getParameter("cstTypeCd");
        //状态
        String isNew = request.getParameter("isNew");
        if (StringUtils.isNumeric(cstId)) {
            qc.setCstId(Long.parseLong(cstId));
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotEmpty(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotEmpty(crtUsrNm)) {
            qc.setCrtUsrNm(crtUsrNm);
        }
        if (StringUtils.isNotEmpty(signResCd)) {
            qc.setSignResCd(signResCd);
        }
        if (StringUtils.isNotEmpty(signResType)) {
            qc.setSignResType(signResType);
        }
        if (StringUtils.isNotEmpty(signSource)) {
            qc.setSignSource(signSource);
        }
        if (StringUtils.isNotEmpty(cstIdcard) && !"null".equals(cstIdcard)) {
            qc.setCstIdcard(cstIdcard);
        }
        if (StringUtils.isNotEmpty(cstTypeCd)) {
            qc.setCstTypeCd(cstTypeCd);
        }
        if (StringUtils.isNotEmpty(isNew)) {
            qc.setIsNew(Integer.valueOf(isNew));
        }
        page.setCondition(qc);

        BaseLogUtils.info(logger, "initRskCstSignLogList", "初始化RskCstSignLog列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = this.rskCstSignLogService.searchListPage(page);
        List<RskCstSignLogVO> rskCstSignLogVOList = (List<RskCstSignLogVO>) pager.getResultList();
        /*List<RskCstSignLogVO> rskCstSignLogVOList = new ArrayList<>();
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //客户关系属性
        JSONArray cstRlTypCdJA = this.cstBscInfoService.searchCstRlTypArray();

        // 获取最早起租日期
        String earlistRtDt = "";
        // 融资额计算
        Double temp = 0d;
        // 保存所有日期
        List<Date> dates = new ArrayList<>();
        if (list != null) {
            // 获取当前的风险标记对象
            for (RskCstSignLogVO rskCstSignLogVO : list) {
                Long prjId = rskCstSignLogVO.getPrjId();
                if (prjId != null && !"".equals(prjId)) {
                    // 设置查询条件，查询设备数量
                    PrjPrdPaySchMQueryCondition qcPrdPaySchM = new PrjPrdPaySchMQueryCondition();
                    qcPrdPaySchM.setPrjId(prjId);
                    qcPrdPaySchM.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
                    // 支付表主表信息
                    List<PrjPrdPaySchMVO> prjPrdPaySchMVOList = prjPrdPaySchMService.searchList(qcPrdPaySchM);
                    rskCstSignLogVO.setPrdCount(Long.valueOf(prjPrdPaySchMVOList.size()));
                    // 获取保证金
                    Long arAmt = prjPrdPaySchMService.searchAramtByPrjId(prjId);
                    if (arAmt == null) {
                        arAmt = 0L;
                    }
                    // 获取剩余本金
                    Long restCorpus = prjPrdPaySchMService.selectRestCorpus(prjId);
                    if (restCorpus == null) {
                        restCorpus = 0L;
                    }
                    // 当前敞口
                    Long open = restCorpus - arAmt;
                    rskCstSignLogVO.setOpen(open);
                    if (prjPrdPaySchMVOList.size() > 1) {
                        for (int i = 0; i < prjPrdPaySchMVOList.size(); i++) {
                            Date date = prjPrdPaySchMVOList.get(i).getLsDt();
                            if (date != null) {
                                dates.add(date);
                            }
                            // 计算融资额
                            temp += prjPrdPaySchMVOList.get(i).getActLsAmt();
                        }
                        if (dates.size() != 0) {
                            ComparatorDate c = new ComparatorDate();
                            Collections.sort(dates, c);
                            earlistRtDt = sdf.format(dates.get(0));
                        }
                    } else if (prjPrdPaySchMVOList.size() == 1) {
                        Date lsDt = prjPrdPaySchMVOList.get(0).getLsDt();
                        if (lsDt != null) {
                            earlistRtDt = sdf.format(prjPrdPaySchMVOList.get(0).getLsDt());
                        } else {
                            earlistRtDt = "";
                        }
                        temp = prjPrdPaySchMVOList.get(0).getActLsAmt();
                    }
                    rskCstSignLogVO.setEarlistRtDt(earlistRtDt);
                    // 数据精度的格式化
                    java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
                    nf.setGroupingUsed(false);
                    String actLsAmt = nf.format(temp);
                    rskCstSignLogVO.setActLsAmt(actLsAmt);
                    // 获取项目基础信息
                    PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjId);

                    // 查询数据库字典，查询项目类型
                    List<KeyValueVO> prjTypeList = this.sysDictionaryApiService.getKvListAll(DictionaryConstant.CODE_PRJ_TYPE_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
//                    List<KeyValueVO> prjTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_PRJ_TYPE_CD);
                    for (KeyValueVO prjTyp : prjTypeList) {
                        if (prjTyp.getKey().equals(prjBscInfoVO.getPrjTypCd())) {
                            rskCstSignLogVO.setPrjTyp(prjTyp.getValue());
                        }
                    }
                    // 查询数据库字典，查询事业部
                    List<KeyValueVO> buOrgList = this.cstBscInfoService.searchBusinessOrgList();
                    for (KeyValueVO buOrg : buOrgList) {
                        if (buOrg.getKey().equals(prjBscInfoVO.getBuOrgCd())) {
                            rskCstSignLogVO.setBuOrg(buOrg.getValue());
                        }
                    }
                }
                // 查询数据库字典，查询客户风险标记原因迁移到实现层
                *//*List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
                for (KeyValueVO signRes : signResCdList) {
                    if (signRes.getKey().equals(rskCstSignLogVO.getSignResCd())) {
                        rskCstSignLogVO.setSignResNm(signRes.getValue());
                    }
                }*//*

                rskCstSignLogVOList.add(rskCstSignLogVO);
            }
        }*/
        ListPageVO<RskCstSignLogVO> listPage = new ListPageVO<RskCstSignLogVO>(rskCstSignLogVOList, pager.getTotalCount());
        return listPage;
    }

    /**
     * 删除单条数据
     */
//    @RequestMapping(value = "/removeById.do", method = {RequestMethod.GET, RequestMethod.POST})
//    @ResponseBody
//    public DataResultVO removeRskCstSignLogById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
//        // 风险标记的主键
//        String id = request.getParameter("id");
//        // 客户id
//        Long cstId = Long.valueOf(request.getParameter("cstId"));
//        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
//        if (StringUtils.isEmpty(id)) {
//            result.setSuccess(BaseConstant.IS_YESNO_NO);
//            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
//            BaseLogUtils.info(logger, "removeCstCertById", "删除客户证件记录表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
//            return result;
//        }
//        try {
//            boolean success = this.rskCstSignLogService.removeById(Long.valueOf(id));
//            if (!success) {
//                result.setSuccess(BaseConstant.IS_YESNO_NO);
//                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
//                BaseLogUtils.info(logger, "removeCstCertById", "删除客户证件记录表信息失败,ID:" + id, CurrentThreadContext.getCurrentUserName());
//            } else {
//                BaseLogUtils.info(logger, "removeCstCertById", "删除客户证件记录表信息成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
//            }
//        } catch (BaseException ex) {
//            result.setSuccess(BaseConstant.IS_YESNO_NO);
//            result.setInfo(ex.getMessage());
//            BaseLogUtils.info(logger, "removeCstCertById", "删除客户证件记录表信息失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
//        } catch (Exception ex) {
//            result.setSuccess(BaseConstant.IS_YESNO_NO);
//            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//            BaseLogUtils.error(logger, "removeCstCertById", "删除客户证件记录表信息失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
//        }
//        // 查询还有没有剩下的标记
//        RskCstSignLogQueryCondition qc = new RskCstSignLogQueryCondition();
//        qc.setCstId(cstId);
//        int rskCstSignLogVOListCount = rskCstSignLogService.searchList(qc).size();
//        if (rskCstSignLogVOListCount == 0) {
//            // 获取VO
//            CstBscInfoVO cstBscInfoVO = cstBscInfoService.selectById(cstId);
//            CstNpBscInfoVO cstNpBscInfoVO = cstNpBscInfoService.selectById(cstId);
//            cstBscInfoVO.setCstNpBscInfoVO(cstNpBscInfoVO);
//            cstBscInfoVO.setId(cstId);
//            cstBscInfoVO.setMdfTm(new Date());
//            cstBscInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
//            // 风险标记
//            cstBscInfoVO.setRskMarkerCd("0");
//            this.rskCstSignLogService.modifyCstRskInfo(CstBscInfoVOTransform.toDTO(cstBscInfoVO));
//        }
//        return result;
//    }


    /**
     * 批量删除数据
     */
    @RequestMapping(value = "/removeByIds.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeRskCstSignLogByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        String cstIds = request.getParameter("cstIds");
        String signRem = request.getParameter("signRem");
        String rskSign = request.getParameter("rskSign");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeRskCstSignLogByIds", "删除RskCstSignLog数据,主键参数为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        // 删除客户风险标记数据
        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }

        try {
            boolean success = this.rskCstSignLogService.removeByIds(idsList);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeRskCstSignLogByIds", "删除RskCstSignLog数据失败,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "removeRskCstSignLogByIds", "删除RskCstSignLog数据成功,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "removeRskCstSignLogByIds", "删除RskCstSignLog数据失败,ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeRskCstSignLogByIds", "删除RskCstSignLog数据失败,系统错误.ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        // 获得多个客户风险标记原因集合并添加操作日志
        List<net.sf.json.JSONObject> rskSignVOList = new ArrayList<net.sf.json.JSONObject>();
        if (StringUtils.isNotEmpty(rskSign)) {
            JSONArray rskSignArray = JSONArray.fromObject(rskSign);
            for (Object object : rskSignArray) {
                rskSignVOList.add((net.sf.json.JSONObject) object);
            }

            for (net.sf.json.JSONObject rskCstSignLogVO : rskSignVOList) {
                RskSignOperLogVO rskSignOperLogVO = new RskSignOperLogVO();
                rskSignOperLogVO.setSignTypCd(RskSignOperLogConstant.SIGN_TYP_CD_CST);
                rskSignOperLogVO.setOperTypCd(RskSignOperLogConstant.OPER_TYP_CD_DEL);
                rskSignOperLogVO.setSignResCd(rskCstSignLogVO.getString("signResCd"));
                rskSignOperLogVO.setSignRem(signRem);
                rskSignOperLogVO.setBizId(rskCstSignLogVO.getLong("cstId"));
                rskSignOperLogVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                rskSignOperLogVO.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());
                rskSignOperLogVO.setCrtTm(new Date());
                rskSignOperLogService.add(rskSignOperLogVO);
            }
        }

        // 更改客户基础信息表的字段
        List<Long> cstIdsList = new ArrayList<Long>();
        if (StringUtils.isNotEmpty(cstIds)) {
            JSONArray cstIdsArray = JSONArray.fromObject(cstIds);
            for (Object object : cstIdsArray) {
                cstIdsList.add(Long.valueOf(object.toString()));
            }
            // 用客户id当做查询条件
            for (Long cstId : cstIdsList) {
                RskCstSignLogQueryCondition qc = new RskCstSignLogQueryCondition();
                qc.setCstId(cstId);
                // 还有没有当前客户的风险标记数据
                int rskCstSignLogCount = rskCstSignLogService.searchList(qc).size();
                if (rskCstSignLogCount == 0) {
                    // 获取VO
                    CstBscInfoVO cstBscInfoVO = cstBscInfoService.selectById(cstId);
                    CstNpBscInfoVO cstNpBscInfoVO = cstNpBscInfoService.selectById(cstId);
                    CstCorpBscInfoVO cstCorpBscInfoVO = cstCorpBscInfoService.selectById(cstId);
                    cstBscInfoVO.setCstCorpBscInfoVO(cstCorpBscInfoVO);
                    cstBscInfoVO.setCstNpBscInfoVO(cstNpBscInfoVO);
                    cstBscInfoVO.setId(cstId);
                    cstBscInfoVO.setMdfTm(new Date());
                    cstBscInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                    // 风险标记
                    cstBscInfoVO.setRskMarkerCd("0");
                    this.rskCstSignLogService.modifyCstRskInfo(CstBscInfoVOTransform.toDTO(cstBscInfoVO));
                }
            }
        }
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getRskCstSignLogById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getRskCstSignLogById", "获取RskCstSignLog数据,主键参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            RskCstSignLogVO vo = this.rskCstSignLogService.selectById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getRskCstSignLogById", "获取RskCstSignLog数据不存在,ID:" + id, CurrentThreadContext.getCurrentUserName());
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getRskCstSignLogById", "获取RskCstSignLog数据成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "getRskCstSignLogById", "获取RskCstSignLog数据失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getRskCstSignLogById", "获取RskCstSignLog数据失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addRskCstSignLog(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        RskCstSignLogVO entity = null;//获取参数
        try {
            entity = this.getRequestParamForRskCstSignLog(request);//获取参数
            Long id = this.rskCstSignLogService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "addRskCstSignLog", "新增RskCstSignLog数据成功,ID:" + id + ".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addRskCstSignLog", "新增RskCstSignLog数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addRskCstSignLog", "新增RskCstSignLog数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyRskCstSignLog(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskCstSignLogVO entity = null;
        try {
            entity = this.getRequestParamForRskCstSignLog(request);//获取参数
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            entity.setMdfUsrNm(CurrentThreadContext.getCurrentUserName());
            entity.setMdfTm(new Date());

            boolean success = this.rskCstSignLogService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyRskCstSignLog", "修改RskCstSignLog数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "modifyRskCstSignLog", "修改RskCstSignLog数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyRskCstSignLog", "修改RskCstSignLog数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyRskCstSignLog", "修改RskCstSignLog数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 删除客户风险标记时填写原因
     */
    @RequestMapping(value = "/toDeleteAndReasonPage.do", method = {RequestMethod.GET})
    @ResponseBody
    public ModelAndView toDeleteAndReasonPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.info(logger, "toDeleteAndReasonPage", "删除客户风险标记时填写原因.", CurrentThreadContext.getCurrentUserName());
        String ids = request.getParameter("ids");
        String cstIds = request.getParameter("cstIds");
        String rskSign = request.getParameter("rskSign");
        // 跳转的页面model对象
        ModelAndView mav = new ModelAndView("risk/rskCstSignLog/toDeleteAndReasonPage");
        mav.addObject("ids", ids);
        mav.addObject("cstIds", cstIds);
        mav.addObject("rskSign", rskSign);
        return mav;
    }

    /**
     * 非备案主体新增或修改页面
     * @param request
     * @param response
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/toNoRecordMainAddOrModifyPage.do", method = {RequestMethod.GET})
    @ResponseBody
    public ModelAndView toNoRecordMainAddOrModifyPage(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.info(logger, "toNoRecordMainAddOrModifyPage", "非备案主体新增或修改.", CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");

        ModelAndView modelAndView = new ModelAndView("risk/rskCstSignLog/noRecordMainAddAndModify");
        // 查询数据库字典，查询客户风险标记原因
        List<KeyValueVO> signResCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CUST_RISK_REASON);
        // 查询数据库字典，查询风险标记类型
        List<KeyValueVO> signResTypeList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CODE_GRP_NM_SIGN_RES_TYPE);
        // 查询数据库字典，查询客户风险标记类型
        List<KeyValueVO> riskTypeCdList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_TYPE_CD);
        // 查询数据库字典，查询客户风险标记风险来源
        List<KeyValueVO> signSourceList = this.rskCstSignLogService.searchCdList(DictionaryConstant.CST_RISK_SING_SOURCE);
        List<KeyValueVO> isValidList = new ArrayList<>();
        KeyValueVO keyValueVO1 = new KeyValueVO();
        keyValueVO1.setKey("1");
        keyValueVO1.setValue("有效");
        isValidList.add(keyValueVO1);
        KeyValueVO keyValueVO2 = new KeyValueVO();
        keyValueVO2.setKey("0");
        keyValueVO2.setValue("无效");
        isValidList.add(keyValueVO2);

        modelAndView.addObject("id", id);
        //新增、修改设置标记时间及标记人
        if (StringUtils.isEmpty(id)) {
            modelAndView.addObject("crtTm", DateUtils.formatDateToString(new Date(),DateUtils.YYYY_MM_DDHHMMSS));
            modelAndView.addObject("crtUserName", CurrentThreadContext.getCurrentUserName());
        } else {
            modelAndView.addObject("mdfTm", DateUtils.formatDateToString(new Date(),DateUtils.YYYY_MM_DDHHMMSS));
            modelAndView.addObject("mdfUserName", CurrentThreadContext.getCurrentUserName());
        }

        modelAndView.addObject("signResCdListJson", JSON.toJSONString(signResCdList));
        modelAndView.addObject("signResTypeListJson", JSON.toJSONString(signResTypeList));
        modelAndView.addObject("signSourceListJson", JSON.toJSONString(signSourceList));
        modelAndView.addObject("riskTypeCdListJson", JSON.toJSONString(riskTypeCdList));
        modelAndView.addObject("isValidListJson", JSON.toJSONString(isValidList));

        return modelAndView;
    }

    /**
     * 校验为未备案主体
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/checkIsNoRecordMain.do", method = {RequestMethod.GET})
    @ResponseBody
    public DataResultVO checkIsNoRecordMain(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO();
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "checkIsNoRecordMain", "checkIsNoRecordMain,主键参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            DataResultDTO resultDTO = this.rskCstSignLogService.checkIsRecordMain(Long.valueOf(id));
            result.setSuccess(resultDTO.getSuccess());
            result.setInfo(resultDTO.getInfo());
            result.setData(resultDTO.getData());
            BaseLogUtils.info(logger, "checkIsNoRecordMain", "checkIsNoRecordMain成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "checkIsNoRecordMain", "checkIsNoRecordMain失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "checkIsNoRecordMain", "checkIsNoRecordMain失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 获取请求参数
     *
     * @param request 请求
     * @return
     */
    private RskCstSignLogVO getRequestParamForRskCstSignLog(HttpServletRequest request) throws BaseException {
        //获取参数
        String id = request.getParameter("id");//id
        String cstId = request.getParameter("cstId");//客户ID
        String cstNm = request.getParameter("cstNm");//客户名称
        String prjId = request.getParameter("prjId");//项目ID
        String lsCntNo = request.getParameter("lsCntNo");//合同号
        String signResCd = request.getParameter("signResCd");//标记原因 1.顶名购买 2.团单拆单 3.老赖 4.诈骗 5.法律纠纷 6.他人运营 7.私下转账 8.代收代付
        String crtUsrNm = request.getParameter("crtUsrNm");// 标记人名称
        String signRem = request.getParameter("signRem");//备注
        String signResType = request.getParameter("signResType");//标记类型
        String cstIdcard = request.getParameter("cstIdcard");//证件号码
        String signSource = request.getParameter("signSource");//标记类型
        String cstTypeCd = request.getParameter("cstTypeCd");//标记类型
        String isValid = request.getParameter("isValid");//标记类型
        String isNoRecord = request.getParameter("isNoRecord");//是否为未备案主体（已备案主体客户Id不能为空）

        //验证参数并赋值
        RskCstSignLogVO entity = new RskCstSignLogVO();
        //未备案主体没有客户ID
        if (!BaseConstant.IS_YESNO_YES_STR.equals(isNoRecord)) {
            if (StringUtils.isNotBlank(cstId)) {
                entity.setCstId(Long.parseLong(cstId));//客户ID
            } else {
                throw new BaseException("客户ID为空!");
            }
        }
        if (StringUtils.isNotBlank(cstNm)) {
            entity.setCstNm(cstNm);//客户名称
        }else{
            throw new BaseException("客户名称为空!");
        }
        if (StringUtils.isNotBlank(prjId)) {
            entity.setPrjId(Long.parseLong(prjId));//项目ID
        }
        if (StringUtils.isNotBlank(lsCntNo)) {
            entity.setLsCntNo(lsCntNo);//合同号
        }
        if (StringUtils.isNotBlank(crtUsrNm)) {
            entity.setCrtUsrNm(crtUsrNm);// 当前用户名称
        }
        if (StringUtils.isNotBlank(signResCd)) {
            entity.setSignResCd(signResCd);//标记原因 1.顶名购买 2.团单拆单 3.老赖 4.诈骗 5.法律纠纷 6.他人运营 7.私下转账 8.代收代付
        }
        if (StringUtils.isNotBlank(signRem)) {
            entity.setSignRem(signRem);//备注
        }
        if(StringUtils.isNotBlank(signResType)){
            entity.setSignResType(signResType);
        }else{
            throw new BaseException("标记类型为空!");
        }
        if(StringUtils.isNotBlank(cstIdcard)){
            entity.setCstIdcard(cstIdcard);
        }else{
            throw new BaseException("客户证件号码为空!");
        }
        if(StringUtils.isNotBlank(signSource)){
            entity.setSignSource(signSource);
        }else{
            throw new BaseException("风险来源为空!");
        }
        if(StringUtils.isNotBlank(cstTypeCd)){
            entity.setCstTypeCd(cstTypeCd);
        }else{
            throw new BaseException("客户类型为空!");
        }
        if(StringUtils.isNotBlank(isValid)){
            entity.setIsValid(Integer.valueOf(isValid));
        }else{
            throw new BaseException("状态为空!");
        }

        entity.setIsDel(BaseConstant.IS_YESNO_NO);
        entity.setIsNew(BaseConstant.IS_YESNO_YES);
        entity.setCrtTm(new Date());
        entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        entity.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());

        return entity;
    }
    /**
     * 获取客户风险标记日志请求参数
     *
     * @param request 请求
     * @return
     */
    private RskSignOperLogVO getRequestParamForRskSignOperLog(HttpServletRequest request) throws BaseException {
        //获取参数
        String bizId = request.getParameter("cstId");//客户ID
        String signResCd = request.getParameter("signResCd");//RSK0018标记原因 0.顶名购买 1.团单拆单2.老赖 3.诈骗 4.法律纠纷 5.他人运营 6.私下转账 7.代收代付 8.黑名单
        String signRem = request.getParameter("signRem");//操作备注
        String signResType = request.getParameter("signResType");//标记类型

        //验证参数并赋值
        RskSignOperLogVO entity = new RskSignOperLogVO();
        entity.setSignTypCd(RskSignOperLogConstant.SIGN_TYP_CD_CST);//标记种类：1.客户 2.设备
        if (StringUtils.isNotEmpty(bizId)) {
            entity.setBizId(Long.valueOf(bizId));//客户ID
        }
        entity.setSignResCd(signResCd);//RSK0018标记原因 0.顶名购买 1.团单拆单2.老赖 3.诈骗 4.法律纠纷 5.他人运营 6.私下转账 7.代收代付 8.黑名单
        entity.setSignResType(signResType);
        entity.setSignRem(signRem);//操作备注

        Date tm = new Date();
        entity.setCrtTm(tm);
        entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        entity.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());

        return entity;
    }

    /**
     * 验证客户风险状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/searchRskSts.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object searchRskSts(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String prjId = request.getParameter("prjId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(prjId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "searchRskSts", "获取searchRskSts数据,主键参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            //获取风险状态（l立项控制状态(标记灰名单或黑名单,只能驳回或不通过操作)  判断客户标记、设备标记 有一个命中 即命中规则）
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            List<Long> prjPrdDtlIds = new ArrayList<Long>();
            PrjPrdDtlQueryCondition dtlQC = new PrjPrdDtlQueryCondition();
            dtlQC.setPrjId(Long.valueOf(prjId));
            List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(dtlQC);
            if(CollectionUtils.isNotEmpty(dtlList)){
                for(PrjPrdDtlVO prjPrdDtlVO : dtlList){
                    prjPrdDtlIds.add(prjPrdDtlVO.getId());
                }
            }
            DataResultDTO rskSts = rskCstSignLogService.searchRskSts(prjBscInfoVO.getCstId(),prjPrdDtlIds);
            BaseLogUtils.info(logger, "searchRskSts", "searchRskSts-风险标记控制-返回结果：" + JSON.toJSONString(rskSts) + "-项目ID:" + prjId);
            if (rskSts!= null && rskSts.getSuccess() == BaseConstant.IS_YESNO_NO){
                BaseLogUtils.info(logger,"searchRskSts","searchRskSts-风险标记控制" + rskSts.getInfo() + "-项目ID:" + prjId);
                throw new BaseException(rskSts.getInfo());
            }
            BaseLogUtils.info(logger, "searchRskSts", "获取searchRskSts数据成功,ID:" + prjId, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "searchRskSts", "获取searchRskSts数据失败,ID:" + prjId + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("客户风险标识判断错误");
            BaseLogUtils.error(logger, "searchRskSts", "获取searchRskSts数据失败,系统错误.ID:" + prjId + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        BaseLogUtils.info(logger, "searchRskSts", "searchRskSts-返回结果:" + JSON.toJSONString(result) + "-项目ID:" + prjId);
        return result;
    }


    /**
     * 初始化客户列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initCstList.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object initCstList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        List<RskCstSignLogVO> rskCstSignLogVOList = null;
        Pager pager = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        // 客户
        String cstNm = request.getParameter("cstNm");
        // 证件号码
        String cstIdcard = request.getParameter("cstIdcard");
        //风险来源
        String signSource = request.getParameter("signSource");
        if(StringUtils.isEmpty(signSource) || SplRelLogBizTypCdNum.CST.getBizTypCd().equals(signSource)){
            CstBscInfoQueryCondition qc = new CstBscInfoQueryCondition();
            if (StringUtils.isNotEmpty(cstNm)) {
                qc.setCstNm(cstNm);
            }
            if (StringUtils.isNotEmpty(cstIdcard)) {
                qc.setCertNo(cstIdcard);
            }
            qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            qc.setCurrUsrId(CurrentThreadContext.getCurrentUserId());
            qc.setIsAuth(true);
            qc.setOpUsrId(CurrentThreadContext.getCurrentUserId());
            page.setCondition(qc);
            pager = this.cstBscInfoService.searchListPage(page);
            List<CstBscInfoVO> list = (List<CstBscInfoVO>) pager.getResultList();
            if(CollectionUtils.isNotEmpty(list)){
                rskCstSignLogVOList = new ArrayList<>();
                for (CstBscInfoVO cstBscInfoVO : list) {
                    RskCstSignLogVO rskCstSignLogVO = new RskCstSignLogVO();
                    rskCstSignLogVO.setCstId(cstBscInfoVO.getId());
                    rskCstSignLogVO.setCstNm(cstBscInfoVO.getCstNm());
                    rskCstSignLogVO.setCstIdcard(cstBscInfoVO.getCertNo());
                    rskCstSignLogVO.setSignSource(SplRelLogBizTypCdNum.CST.getBizTypCd());
                    rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.CST.getBizTypCdNm());
                    rskCstSignLogVOList.add(rskCstSignLogVO);
                }
            }
        }else if(SplRelLogBizTypCdNum.SPL.getBizTypCd().equals(signSource)){
            SplInfoQueryCondition qc = new SplInfoQueryCondition();
            qc.setIsDel(BaseConstant.IS_YESNO_NO);
            if (StringUtils.isNotBlank(cstNm)) {
                qc.setSplNm(cstNm);
            }
            if(StringUtils.isNotEmpty(cstIdcard)){
                qc.setSucc(cstIdcard);
            }
            qc.setIsBlackList(BaseConstant.IS_RELOGIN_FLAG);
            page.setCondition(qc);
            BaseLogUtils.newWebLogger("初始化供应商列表页面数据.DATA:"+JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
            pager = this.splInfoService.searchListPage(page);
            BaseLogUtils.newWebLogger("获取供应商列表页面数据.DATA:"+JSONObject.toJSONString(pager)).setLogOperType(LogOperEnum.RESP)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .info();
            List<SplInfoVO> list = (List<SplInfoVO>) pager.getResultList();
            if(CollectionUtils.isNotEmpty(list)) {
                rskCstSignLogVOList = new ArrayList<>();
                for (SplInfoVO splInfoVO : list) {
                    RskCstSignLogVO rskCstSignLogVO = new RskCstSignLogVO();
                    rskCstSignLogVO.setCstId(splInfoVO.getId());
                    rskCstSignLogVO.setCstNm(splInfoVO.getSplNm());
                    rskCstSignLogVO.setCstIdcard(splInfoVO.getSucc());
                    rskCstSignLogVO.setSignSource(SplRelLogBizTypCdNum.SPL.getBizTypCd());
                    rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.SPL.getBizTypCdNm());
                    rskCstSignLogVOList.add(rskCstSignLogVO);
                }
            }
        }else if(SplRelLogBizTypCdNum.LNK.getBizTypCd().equals(signSource)){
            PrjLnkCompQueryCondition qc = new PrjLnkCompQueryCondition();
            if (StringUtils.isNotEmpty(cstNm)) {
                qc.setLnkCompNm(cstNm);
            }
            if (StringUtils.isNotEmpty(cstIdcard)) {
                qc.setSucc(cstIdcard);
            }
            qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            page.setCondition(qc);
            pager = this.prjLnkCompService.searchListPage(page);
            List<PrjLnkCompVO> list = (List<PrjLnkCompVO>) pager.getResultList();
            if(CollectionUtils.isNotEmpty(list)) {
                rskCstSignLogVOList = new ArrayList<>();
                for (PrjLnkCompVO prjLnkCompVO : list) {
                    RskCstSignLogVO rskCstSignLogVO = new RskCstSignLogVO();
                    rskCstSignLogVO.setCstId(prjLnkCompVO.getId());
                    rskCstSignLogVO.setCstNm(prjLnkCompVO.getLnkCompNm());
                    rskCstSignLogVO.setCstIdcard(prjLnkCompVO.getSucc());
                    rskCstSignLogVO.setSignSource(SplRelLogBizTypCdNum.LNK.getBizTypCd());
                    rskCstSignLogVO.setSignSourceNm(SplRelLogBizTypCdNum.LNK.getBizTypCdNm());
                    rskCstSignLogVOList.add(rskCstSignLogVO);
                }
            }
        }
        if(CollectionUtils.isNotEmpty(rskCstSignLogVOList)){
            for(RskCstSignLogVO rskCstSignLogVO : rskCstSignLogVOList){
                RskCstSignLogQueryCondition qc = new RskCstSignLogQueryCondition();
                qc.setIsNew(BaseConstant.IS_YESNO_YES);
                qc.setIsDel(BaseConstant.IS_YESNO_NO);
                qc.setCstId(rskCstSignLogVO.getCstId());
                qc.setCstNm(rskCstSignLogVO.getCstNm());
                qc.setCstIdcard(rskCstSignLogVO.getCstIdcard());
                qc.setSignSource(rskCstSignLogVO.getSignSource());
                List<RskCstSignLogVO> list = this.rskCstSignLogService.searchList(qc);
                if(CollectionUtils.isNotEmpty(list)){
                    rskCstSignLogVO.setSignResTypeNm(list.get(0).getSignResTypeNm());
                    rskCstSignLogVO.setId(list.get(0).getId());
                }
            }
        }
        ListPageVO<RskCstSignLogVO> listPage = new ListPageVO<RskCstSignLogVO>(rskCstSignLogVOList, pager.getTotalCount());
        return listPage;
    }



}

